﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication2.Util
{
    /// <summary>
    /// ID生成器
    /// 返回当前时间的年月日时分秒+两位随机数拼接成的字符串
    /// </summary>
    public class IdUtil
    {
        public static String GetId() {
            int year, mouth, day, hour, min, sec, ms, suiji;
            //获取当前时间
            DateTime DT = DateTime.Now;
            year = (DT.Year) % 100;
            mouth = DT.Month;
            day = DT.Day;
            hour = DT.Hour;
            min = DT.Minute;
            sec = DT.Second;
            ms = DT.Millisecond;
            //生成随机数，大于等于100，小于1000
            Random rad = new Random();
            suiji = rad.Next(10, 100);
            //打印当前时间+3随机数
            Console.WriteLine("{0:00}{1:00}{2:00}{3:00}{4:00}", year, mouth, day, hour, min);

            long a = suiji + min * 100 + hour * 10000 + day * 1000000 + mouth * 100000000 + year * 10000000000;
            return a.ToString();
        }
    }
}